$(document).ready(function(){
	init();
    monitor();
    service();
});

function init(){
    load(1);
}
function monitor(){
    $(".g-fair-task-info .u-content-btn").on("click",function(){
    	var status =  $(this).attr("data-status");
    	if(status=="off"){
    		$(".g-fair-task-info .m-cell-active").removeClass("m-cell-active");
            $(this).parent().parent().parent().addClass("m-cell-active");
            $(".u-content-btn").each(function (i,item){
            	// console.log(item);
            	$(item).attr("data-status","off");
            });
            $(this).attr("data-status","open");
    	}else{
    		$(".g-fair-task-info .m-cell-active").removeClass("m-cell-active");
    		$(this).attr("data-status","off");
    	}
    });
}
function service(){

}

function load(number){
    $.ajax({
        type:"post",
        url:"/platform/fair/detail_task",
        datatype:"json",
        data:{
            pageNum: number,
            pageSize: 4,
            id: $("#fair_id").val()
        },
        success:function(data){
            let _html = "";
            if(data.taskPage.list.length>0){
                for (var i=0;i<data.taskPage.list.length;i++){
                    const item = data.taskPage.list[i];
                    var h="";
                    var count=0;
                    if (item.evaluate_issuer!=null || item.evaluate_whom !=null){
                        h+='<ul class="m-more">';
                        if (item.evaluate_issuer!=null){
                            count++;
                            h+='<li class="m-more-cell">'+
                            '<div class="u-more-value" style="width:400px;">'+
                            '<div class="u-more-head"></div>'+
                            '<div class="u-more-name">'+item.cmp+'</div>'+
                            '</div>'+
                            '<div class="u-more-value-mid">'+item.evaluate_issuer+'</div>'+
                            '<div class="u-more-value">'+item.issuer_date+'</div>'+
                            '</li>';
                        }
                        if (item.evaluate_whom!=null){
                            count++;
                            h+='<li class="m-more-cell">'+
                            '<div class="u-more-value" style="width:400px;">'+
                            '<div><img src="'+item.img+'" style="border-radius:25px;" width="50"/></div>'+
                            '<div class="u-more-name">'+item.whn+'</div>'+
                            '</div>'+
                            '<div class="u-more-value-mid">'+item.evaluate_whom+'</div>'+
                            '<div class="u-more-value">'+item.whom_date+'</div>'+
                            '</li>';
                        }
                        h+='</ul>';
                    }
                    _html += '<li class="m-cell">'+
                    '<div class="m-content">'+
                    '<div class="u-content-value" style="flex:1.5">'+item.dateString+'</div>'+
                    '<div class="u-content-value" style="padding-left:10px;display:flex;justify-content:flex-start;flex:2">'+item.title+'</div>'+
                    '<div class="u-content-value" style="flex:1.5">点击量:'+item.click_num+' | 转化量:'+item.cvs_num+'</div>'+
                    '<div class="u-content-value">'+item.statusString+'</div>'+
                    '<div class="u-content-value ">'+
                    '<div class="u-content-btn" data-status="off" style="border-radius:3px;">评论（'+count+'）</div>'+
                    '</div>'+
                    '</div>';
                    _html+=h;
                    _html+='</li>';
                }
                page(data.taskPage.totalPage,data.taskPage.pageNumber);
                $("#m_choice_page").show();
            }else{
                _html="<li style='margin:15px;color:red'>暂时没有相关记录信息</li>"
                $("#m_choice_page").hide();
            }
            $("#data").html(_html);
            monitor();
        }
    })
}

function page(total, index){
    laypage({
        cont: 'm_choice_page', //容器。值支持id名、原生dom对象，jquery对象。【如该容器为】：<div id="page1"></div>
        pages: total||1, //通过后台拿到的总页数
        curr: index || 1, //当前页
        jump: function (obj, first) { //触发分页后的回调
            if (!first) { //点击跳页触发函数自身，并传递当前页：obj.curr
                load(obj.curr);
            }
        }
    });
}